<template>
  <div class="container">
    <el-dialog title="审核" :visible="isShowDialog" @close="handleClose">
      <el-radio v-model="radio" value="1" label="1">通过</el-radio>
      <el-radio v-model="radio" value="2" label="2">拒绝</el-radio>
      <el-input class="textarea" type="textarea" placeholder="请输入审核意见" v-model.trim="questionData.chkRemarks"></el-input>
      <el-row class="row-button" type="flex" justify="end">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="audit">确定</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
// 试题审核接口
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'check',
  props: {
    isShow: {
      type: Boolean,
      default: false
    },
    topicData: {
      type: Object,
      required: true
    }
  },
  watch: {
    isShow (newVal) {
      this.isShowDialog = newVal
    },
    topicData (newVal) {
      this.questionData = newVal
    }
  },
  data () {
    return {
      isShowDialog: this.isShow,
      questionData: this.topicData,
      radio: '1'
    }
  },
  methods: {
    // 取消 / 关闭弹层
    handleClose () {
      this.isShowDialog = false
      this.$emit('update:isShow', false)
    },
    // 试题审核
    // 点击确定，发请求
    async audit () {
      const info = this.questionData
      if (!this.questionData.chkRemarks) return this.$message.warning('请输入审核意见')
      info.chkState = +this.radio
      const { data: { success } } = await choiceCheck(info)
      if (!success) return this.$message.error('审核失败')
      this.$emit('update:isShow', false)
      this.$message.success('审核成功')
    }
  }
}
</script>

<style scoped>
  .textarea {
    padding: 30px 0;
  }
  .row-button {
    margin-top: 20px;
  }
</style>
